To date, flash memories, which are nonvolatile semiconductor memories, have been used. A controller controlling such a flash memory writes data and reads data for each plurality of bits called a page, and erases data for each block including a plurality of the pages.
Such a controller performs erase processing of erasing data from a flash memory for each block. And when the controller writes data, the controller searches for a free block in which data was erased, and writes new data on the detected free block.
Also, the controller generates an ECC (Error Correcting Code) which enables detection of erroneous data having been written and correction of data, and stores the ECC with data into the flash memory. Here, a data size of the ECC generated by the controller is determined by a fixed value set by an initial setting.
And when the controller reads data from the flash memory, the controller reads the ECC from the flash memory with data, detects an error of the read data using the ECC, and performs data correction processing.
Incidentally, in the above-described related-art technique, there has been a problem in that a data size of a generated ECC is constant, and thus reliability of data stored in the flash memory becomes low. That is to say, in a flash memory, cells of the flash memory are deteriorated each time data erase processing and data write processing are performed, and thus a possibility of writing erroneous data becomes high.
Accordingly, when a data size of an ECC for data stored in a deteriorated cell is small, it is not possible to correct the data properly, and thus reliability of the data stored in the flash memory becomes low. In this regard, it is thought that the reliability of the data is improved by increasing the data size of the ECC uniformly. However, it takes more time for data-error detection processing and data correction processing with an increase in the data size of the ECC. Accordingly, it also takes time for data-error detection processing and data correction processing on data stored in cells that have not deteriorated, and thus performance of reading data from the flash memory deteriorates.